package com.generation.tool.controller;

import com.generation.tool.pojo.result.R;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import com.generation.tool.pojo.po.Test;
import com.generation.tool.service.ITestService;

/**
 * @Author: 吃我一钊
 * @Description: 控制层
 * @Date: 2025/01/27
 */
@RestController
@RequestMapping("/test")
public class TestController {

	@Autowired
	private ITestService testService;

	/**
	 * 新增数据
	 * @param test
	 * @return
	 */
	@PostMapping("/save")
	public R<Void> save(@RequestBody Test test) {
		testService.save(test);
		return R.ok();
	}

	/**
	 * 根据id删除
	 * @param testId
	 * @return
	 */
	@DeleteMapping("/deleteById/{testId}")
	public R<Void> deleteById(@PathVariable("testId") Integer testId) {
		testService.removeById(testId);
		return R.ok();
	}

	/**
	 * 根据id修改数据
	 * @param test
	 * @return
	 */
	@PutMapping("/updateById")
	public R<Void> updateById(@RequestBody Test test) {
		testService.updateById(test);
		return R.ok();
	}

	/**
	 * 根据id查询数据
	 * @param testId
	 * @return
	 */
	@GetMapping("/getById/{testId}")
	public R<Test> getById(@PathVariable("testId") Integer testId) {
		Test test = testService.getById(testId);
		return R.ok(test);
	}
	/**
	 * 查询所有数据
	 * @return
	 */
	@GetMapping("/list")
	public R<List<Test>> list() {
		List<Test> testList = testService.list();
		return R.ok(testList);
	}

}